package zwo.controller;

import zwo.dao.CategoryMapper;
import zwo.model.Category;
import zwo.model.dto.CategoryDTO;
import zwo.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    @Resource
    private CategoryMapper categoryMapper;


    @ResponseBody
    @RequestMapping("/cateGoryAll.do")
    public Map cateGoryAll(CategoryDTO categoryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("msg", "");
        map.put("count", categoryMapper.cateCount(categoryDTO));
        map.put("data", categoryMapper.cateGroyAll(categoryDTO));
        return map;
    }

    @ResponseBody
    @RequestMapping("/cateGoryAdd.do")
    public Integer cateGoryAdd(Category category) {
        return categoryService.cateGoryAdd(category);
    }

    @ResponseBody
    @RequestMapping("/cateGoryDelete.do")
    public Integer cateGoryDelete(Category category) {
        return categoryService.cateGoryDelete(category);
    }


    @ResponseBody
    @RequestMapping("/cateSwitchEdit.do")
    public Integer cateSwitchEdit(Category category) {
        return categoryMapper.cateSwitchEdit(category);
    }

    @ResponseBody
    @RequestMapping("/productCateAll.do")
    public Map productCateAll(Category category) {
        Map map = new HashMap();
        map.put("data", categoryMapper.productCateAll());
        return map;
    }

}
